import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.Test;
import us.codecraft.xsoup.Xsoup;

import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * Created by picago on 2015/8/21.
 */
public class learning {

    private String html = "<html><body><div id='test'>aaa<div><a href=\"https://github.com\">" +
            "github.com</a></div></div></body></html>";

    private String htmlClass = "<html><body><div class='a b c'><div><a href=\"https://github.com\">" +
            "github.com</a></div></div><div>b</div> <div a='b'> </div><book price=200 /><book price=100 />" +
            "<book /></body></html>";


    Document document = Jsoup.parse(html);

    @Test
    public void test01() {
        String result = Xsoup.compile("//a/@href").evaluate(document).get();
        assertEquals("https://github.com", result);

        List<String> list = Xsoup.compile("//tr/td/text()").evaluate(document).list();
        assertEquals("a", list.get(0));
        assertEquals("b", list.get(1));
    }

    @Test
    public void testXPath() throws Exception {
        String alink = Xsoup.select(html, "/html/body/a/@href").get();
        assertEquals("https=\"https://github.com\"",alink);
    }
}
